home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77717_site_new.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  42.7 KB  |  1,402 lines

  1. <%@ Language=VBScript   %>
  2. <%    Option Explicit     %>
  3. <%
  4. '    Response.Buffer = True
  5.     '-------------------------------------------------------------------------
  6.     '    site_new.asp: Serves in creating a new site
  7.     '
  8.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  9.     '
  10.     '    Date            Description
  11.     '    14-Jan-2001        Creation Date
  12.     '    25-Jan-2001        Last Modified Date    
  13.     '-------------------------------------------------------------------------
  14. %>
  15.  
  16.     <!-- #include virtual="/admin/inc_framework.asp" -->    
  17.     <!-- #include file="resources.asp" -->
  18.     <!-- #include file="inc_wsa.asp" -->    
  19.     <!-- #include file="Sitenew_prop.asp" -->    
  20. <%
  21.  
  22.     Err.Clear
  23.     'On Error Resume Next
  24.     '-------------------------------------------------------------------------
  25.     ' Global Constants and Variables
  26.     '-------------------------------------------------------------------------
  27.     Dim G_strAnonName        'to hold Anonymous name
  28.     Dim G_strAnonPwd        'to hold Anonymous pwd
  29.     Dim G_strDirRoot        'to hold Domainname value
  30.     Dim G_strSysName        'to hold system name    
  31.     Dim G_Browser_Grp        'to hold Browsers group for AD Scenario
  32.     Dim G_Admin_Grp            'to hold Admin group for AD Scenario
  33.     Dim G_Authors_Grp        'to hold Authors group for AD scenario
  34.     Dim G_strSiteName        'to hold site name    
  35.     Dim G_AnonUserName        'to hold anonymouse username created by IIS    
  36.     
  37.     Dim rc                    'to hold return count value
  38.     Dim page                'to hold page object
  39.     
  40.     Dim idTabGeneral        'to hold Ist tab value
  41.     Dim idTabSiteID            'to hold IInd tab value
  42.     Dim idTabAppSetting        'to hold Vth tab value
  43.     
  44.     '=========================================================================
  45.     ' Entry point
  46.     '=========================================================================
  47.     '
  48.     ' Set username value
  49.     G_AnonUserName = GetIISAnonUsername()
  50.     
  51.     'Create a Tabbed Property Page
  52.     rc = SA_CreatePage( L_CREATETASKTITLE_TEXT, "", PT_TABBED, page )
  53.     
  54.     ' Add five tabs
  55.     rc = SA_AddTabPage( page, L_GENERAL_TEXT, idTabGeneral)
  56.     rc = SA_AddTabPage( page, L_SITEIDENTITY_TEXT, idTabSiteID)
  57.     rc = SA_AddTabPage( page, L_APPLICATIONSETTINGS_TEXT, idTabAppSetting)
  58.     
  59.     ' Show the page
  60.     rc = SA_ShowPage( page )
  61.     
  62.     '=========================================================================
  63.     ' Web Framework Event Handlers
  64.     '=========================================================================
  65.     
  66.     '-------------------------------------------------------------------------
  67.     ' Function:    OnInitPage
  68.     '
  69.     ' Synopsis:    Called to signal first time processing for this page. Use 
  70.     '            this method to do first time initialization tasks. 
  71.     '
  72.     ' Returns:    TRUE to indicate initialization was successful. FALSE to 
  73.     '            indicate errors. Returning FALSE will cause the page to be 
  74.     '            abandoned.
  75.     '
  76.     '-------------------------------------------------------------------------
  77.     Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  78.         On Error Resume Next
  79.     
  80.         Call GetDomainRole( G_strDirRoot, G_strSysName )
  81.         
  82.         'init the checkbox
  83.         F_strCreatePathChecked = "true"
  84.         
  85.         '
  86.         'We won't support create Domain Admin Site anymore
  87.         F_strAccountLocation = "1"
  88.         
  89.         OnInitPage = TRUE
  90.     End Function
  91.     
  92.     '-------------------------------------------------------------------------
  93.     ' Function:    OnPostBackPage
  94.     '
  95.     ' Synopsis:    Called to signal that the page has been posted-back. A post-
  96.     '            back occurs in tabbed property pages and wizards as the user 
  97.     '            navigates through pages. It is differentiated from a Submit
  98.     '            or Close operationin that the user is still working with the 
  99.     '            page.
  100.     '
  101.     '            The PostBack event should be used to save the state of page.
  102.     '
  103.     ' Returns:    TRUE to indicate initialization was successful. FALSE to 
  104.     '            indicate errors. Returning FALSE will cause the page to be 
  105.     '            abandoned.
  106.     '-------------------------------------------------------------------------
  107.     Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)        
  108.         Err.clear
  109.         on Error Resume Next
  110.     
  111.         'get variables from form
  112.         call SetGenFormVariables()
  113.         
  114.         call SetSiteIdentitiesFormVariables()
  115.         
  116.         call SetApplnSettingsFormVariables()
  117.  
  118.         Call SA_TRACEOUT("OnPostBackPage","OnPostBackPage called")
  119.  
  120.         OnPostBackPage = TRUE
  121.  
  122.     End Function
  123.  
  124.     
  125.     '--------------------------------------------------------------------------
  126.     ' Function:    OnServeTabbedPropertyPage
  127.     '
  128.     ' Synopsis:    Called when the page needs to be served. Use this method to
  129.     '            serve content.
  130.     '
  131.     ' Returns:    TRUE to indicate not problems occured. FALSE to indicate errors.
  132.     '            Returning FALSE will cause the page to be abandoned.
  133.     '
  134.     '--------------------------------------------------------------------------
  135.     Public Function OnServeTabbedPropertyPage(ByRef PageIn, _
  136.                                             ByVal iTab, _
  137.                                             ByVal bIsVisible, _
  138.                                             ByRef EventArg)
  139.         ' Emit Web Framework required functions
  140.         If ( iTab = idTabGeneral) Then
  141.             Call ServeCommonJavaScript()
  142.         End If        
  143.  
  144.         ' Emit content for the requested tab
  145.         Select Case iTab            
  146.             Case idTabGeneral
  147.                 Call ServeTabGeneral(PageIn, bIsVisible)
  148.             Case idTabSiteID
  149.                 Call ServeTabSiteID(PageIn, bIsVisible)
  150.             Case idTabAppSetting
  151.                 Call ServeTabAppSetting(PageIn, bIsVisible)
  152.             Case Else
  153.                 SA_TraceOut "TEMPLAGE_TABBED", _
  154.                     "OnServeTabbedPropertyPage unrecognized tab id: " + _
  155.                     CStr(iTab)
  156.         End Select
  157.             
  158.         OnServeTabbedPropertyPage = TRUE
  159.     End Function
  160.  
  161.  
  162.     '-------------------------------------------------------------------------
  163.     ' Function:    OnSubmitPage
  164.     '
  165.     ' Synopsis:    Called when the page has been submitted for processing. Use
  166.     '            this method to process the submit request.
  167.     '
  168.     ' Returns:    TRUE if the submit was successful, FALSE to indicate error(s).
  169.     '            Returning FALSE will cause the page to be served again using
  170.     '            a call to OnServePropertyPage.
  171.     '
  172.     '-------------------------------------------------------------------------
  173.     Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)                
  174.         OnSubmitPage = CreateSite()
  175.     End Function
  176.  
  177.     '-------------------------------------------------------------------------
  178.     ' Function:    OnClosePage
  179.     '
  180.     ' Synopsis:    Called when the page is about to be closed. Use this method
  181.     '            to perform clean-up processing.
  182.     '
  183.     ' Returns:    TRUE to allow close, FALSE to prevent close. Returning FALSE
  184.     '            will result in a call to OnServePropertyPage.
  185.     '
  186.     '-------------------------------------------------------------------------
  187.     Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  188.         OnClosePage = TRUE
  189.     End Function
  190.  
  191.  
  192.     '=========================================================================
  193.     ' Private Functions
  194.     '=========================================================================
  195.         
  196.     '-------------------------------------------------------------------------
  197.     'Function name        :ServeTabGeneral
  198.     'Description        :Serves General tab
  199.     'Input Variables    :PageIn, bIsVisible
  200.     'Output Variables    :None
  201.     'Returns            :Success(Return value)
  202.     'Global Variables    :None    
  203.     '-------------------------------------------------------------------------
  204.     Function ServeTabGeneral(ByRef PageIn, ByVal bIsVisible)        
  205.         
  206.         If ( bIsVisible ) Then
  207.  
  208.             call GeneralViewTab()
  209.       
  210.         Else
  211.             'update hidden variables
  212.             call GeneralHiddenTab()
  213.         
  214.          End If
  215.     
  216.         ServeTabGeneral = gc_ERR_SUCCESS
  217.     
  218.     End Function
  219.  
  220.  
  221.     '-------------------------------------------------------------------------
  222.     'Function name        :ServeTabSiteID
  223.     'Description        :Serves the Site identities tab
  224.     'Input Variables    :PageIn, bIsVisible
  225.     'Output Variables    :None
  226.     'Returns            :Success(Return value)
  227.     'Global Variables    :None    
  228.     '-------------------------------------------------------------------------
  229.     Function ServeTabSiteID(ByRef PageIn, ByVal bIsVisible)    
  230.     
  231.         If ( bIsVisible ) Then
  232.  
  233.             call SiteIdentitiesViewTab()
  234.             
  235.         Else
  236.             'update hidden variables 
  237.     
  238.             call SiteIdentitiesHiddenTab()
  239.         
  240.          End If
  241.     
  242.         ServeTabSiteID = gc_ERR_SUCCESS
  243.     
  244.     End Function
  245.     
  246.  
  247.     '-------------------------------------------------------------------------
  248.     'Function name        :ServeTabAppSetting
  249.     'Description        :Serve the Application Settings tab
  250.     'Input Variables    :PageIn, bIsVisible
  251.     'Output Variables    :None
  252.     'Returns            :Success(Return value)
  253.     'Global Variables    :None    
  254.     '-------------------------------------------------------------------------
  255.     Function ServeTabAppSetting(ByRef PageIn, ByVal bIsVisible)    
  256.         
  257.             
  258.         If ( bIsVisible ) Then
  259.  
  260.             call ApplicationSettingsViewTab()
  261.             
  262.         Else 
  263.             'update hidden variables
  264.  
  265.             call ApplicationSettingsHiddenTab()
  266.         
  267.         end if
  268.                 
  269.         ServeTabAppSetting = gc_ERR_SUCCESS
  270.     
  271.     End Function
  272.  
  273.     '-------------------------------------------------------------------------
  274.     ' Function:    ServeCommonJavaScript
  275.     '
  276.     ' Synopsis:    Common javascript functions that are required by the Web
  277.     '            Framework.
  278.     '
  279.     '------------------------------------------------------------------------
  280.     Function ServeCommonJavaScript()
  281.     
  282.         Err.clear
  283.         on Error Resume Next
  284.     
  285.     %>
  286.         <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  287.         </script>
  288.  
  289.         <script language="JavaScript">
  290.         //
  291.         // Microsoft Server Appliance Web Framework Support Functions
  292.         // Copyright (c) Microsoft Corporation.  All rights reserved. 
  293.         //
  294.         // Init Function
  295.         // -----------
  296.         // This function is called by the Property Page web framework to  
  297.         // allow the page to perform first time initialization. 
  298.         //
  299.         // This function must be included or a javascript runtime error will
  300.         // occur.
  301.     
  302.         function Init()
  303.             {                
  304.                 //Get the selected tab
  305.                 var temp = top.main.document.forms['frmTask'].TabSelected.value;
  306.                 
  307.                 switch(temp)
  308.                 {
  309.                     //for General prop
  310.                     case '0':
  311.                         GenInit();
  312.                         break;
  313.                     //for Site prop    
  314.                     case '1':
  315.                         SiteInit();                            
  316.                         break;
  317.                     //for Appl prop
  318.                     case '2':
  319.                         ApplInit();
  320.                         break;    
  321.                 }            
  322.             }
  323.    
  324.         
  325.         
  326.         // ValidatePage Function
  327.         // ------------------
  328.         // This function is called by the Property Page framework as part of 
  329.         // the submit processing. Use this function to validate user input. 
  330.         // Returning false will cause the submit to abort. 
  331.         //
  332.         // This function must be included or a javascript runtime error will 
  333.         // occur.
  334.         // Returns: True if the page is OK, false if error(s) exist. 
  335.         
  336.         function ValidatePage()
  337.         {
  338.             
  339.             //Get the selected tab
  340.             var temp = top.main.document.forms['frmTask'].TabSelected.value;                    
  341.         
  342.             switch(temp)
  343.             {
  344.                 //for general prop
  345.                 case '0':                        
  346.                     return GenValidatePage();
  347.                     break;
  348.                 //for Site prop    
  349.                 case '1':
  350.                     return SiteValidatePage();
  351.                     break;
  352.                 //for Appl prop    
  353.                 case '2':
  354.                     return ApplValidatePage();
  355.                     break;    
  356.             }
  357.         }
  358.                 
  359.         // SetData Function
  360.         // --------------
  361.         // This function is called by the Property Page framework and is called
  362.         // only if ValidatePage returned a success (true) code. Typically you 
  363.         // would modify hidden form fields at this point. 
  364.         //
  365.         // This function must be included or a javascript runtime error will 
  366.         // occur.
  367.         function SetData()
  368.         {        
  369.  
  370.             //Get the selected tab
  371.             var temp = top.main.document.forms['frmTask'].TabSelected.value;                    
  372.             
  373.             switch(temp)
  374.             {
  375.                 //for general prop
  376.                 case '0':
  377.                     GenSetData();
  378.                     break;
  379.                 //for Site prop    
  380.                 case '1':
  381.                     SiteSetData();
  382.                     break;
  383.                 //for Appl prop
  384.                 case '2':
  385.                     ApplSetData();
  386.                     break;    
  387.             }
  388.         }
  389.         </script>
  390.     <%
  391.     End Function
  392.     
  393.     '----------------------------------------------------------------------------
  394.     'Function name        :CreateSite
  395.     'Description        :Serves in Creating a New Web Site
  396.     'Input Variables    :None 
  397.     'Output Variables    :None
  398.     'Returns            :Boolean (True if new site is created else returns False)
  399.     'Global Variables    :None
  400.     'Functions Used        :blnValidateInputs
  401.     '                     HandleWrkgrpAndNTDC
  402.     '                     blnCreateWebSite
  403.     '                     blnSetDiskQuotas
  404.     '                      blnSetDACLEntry
  405.     '----------------------------------------------------------------------------
  406.     Function CreateSite()
  407.         on error resume next 
  408.         Err.Clear
  409.                 
  410.         Call SA_TraceOut(SA_GetScriptFileName(), "Entering CreateSite()")
  411.         
  412.         Dim objRoot            'holds root object
  413.         Dim strUserName        'hold user name
  414.         Dim WebName            'hold web name
  415.         Dim strBool
  416.         
  417.         CreateSite = FALSE
  418.  
  419.         Call GetDomainRole( G_strDirRoot, G_strSysName )        
  420.  
  421.         Call SA_TraceOut(SA_GetScriptFileName(), "System name: " + CStr(G_strSysName))
  422.         Call SA_TraceOut(SA_GetScriptFileName(), "Directory root: " + CStr(G_strDirRoot))
  423.  
  424.         ' Bind to the root object
  425.         If F_strAccountLocation = "1" Then
  426.             Set objRoot = GetObject("WinNT://" & G_strSysName)
  427.         Else
  428.             Set objRoot = GetObject("WinNT://" & G_strDirRoot)
  429.         End If
  430.  
  431.         If Err.number <> 0 Then
  432.             Call SA_TraceOut(SA_GetScriptFileName(), "Error creating Root object, error: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  433.             Call SA_SetErrMsg(SA_GetLocString("Sitearea.dll", "C04201D4", Array("WinNT://" & G_strDirRoot)))
  434.             Exit Function
  435.         End if
  436.  
  437.         '
  438.         ' If an existing account was specified then the account name needs to be
  439.         ' in the form ComputerName\AccountName. If the user did not enter the name
  440.         ' in this form, then correct the name to match this format.
  441.         If ( F_strAccountLocation = "2" ) Then
  442.             If ( InStr(F_strAdminName, "\") = 0 ) Then
  443.                 F_strAdminName = G_strSysName & "\" & F_strAdminName
  444.             End If
  445.         End If
  446.         
  447.                 
  448.         'user and groups names to be created
  449.         G_strAnonName = F_strSiteID &  "_Anon"  
  450.         G_Browser_Grp = F_strSiteID & "_Browsers"
  451.         G_Admin_Grp = F_strSiteID & "_Admins"
  452.         G_Authors_Grp = F_strSiteID & "_Authors"
  453.  
  454.         '1) verify input datas
  455.         if ( NOT blnValidateInputs()) then
  456.             Call SA_TraceOut(SA_GetScriptFileName(), "Error in input parameters")
  457.             Exit Function
  458.         End If
  459.  
  460.         '2) Create site users and generate the anonymous user's pwd
  461.         If ( NOT CreateSiteUsers(objRoot)) Then
  462.             Call SA_TraceOut(SA_GetScriptFileName(), "CreateSiteUsers error: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  463.             Exit Function
  464.         End If
  465.         
  466.         '3) Create Web site. Use the Admin and Anon users created above for this
  467.         If( NOT blnCreateWebSite(F_strSiteID, _
  468.                               F_strIPAddr, _
  469.                               F_strPort, _
  470.                               F_strHeader, _
  471.                               F_strDir, _
  472.                               F_strchkAllow, _
  473.                               F_selectActiveFormat, _
  474.                               F_strAdminName, _
  475.                               F_strDefaultPageText)) then
  476.             Call SA_TraceOut(SA_GetScriptFileName(),  "CreateWebSite error: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  477.  
  478.             ' If we did not use an existing user account then we need to
  479.             ' delete the accounts we created (see CreateSiteUsers function).
  480.             If (F_strAccountLocation <> "2") Then
  481.                 Call blnDeleteUser(objRoot, F_strAdminName)
  482.                 Call blnDeleteUser(objRoot, G_strAnonName)
  483.             end if
  484.  
  485.              SA_ServeFailurePage L_CREATEFAIL_ERRORMESSAGE
  486.             exit function
  487.         end if 'create site
  488.          
  489.         '4)Config directory DACL
  490.         If(NOT ConfigDirDACL(F_strDir, F_strAdminName)) Then
  491.             Call SA_TraceOut(SA_GetScriptFileName(),  "ConfigDirDACL error: "+ CStr(Hex(Err.Number)) + " " + Err.Description)
  492.             Exit Function
  493.         End If
  494.  
  495.         '6) config virtual FTP site
  496.         If F_strUploadMethod = UPLOADMETHOD_FTP Then
  497.             Dim objService
  498.             Set objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  499.             If (NOT CreateVirFTPSite(objService, F_strAdminName, F_strDir, True, True, True)) Then
  500.                 Call SA_TraceOut(SA_GetScriptFileName(),  "CreateVirFTPSite error: "+ CStr(Hex(Err.Number)) + " " + Err.Description)
  501.                 SetErrMsg L_ERR_CREATE_VIR_FTP_SITE
  502.                 If ( Len(GetErrMsg()) <= 0 ) Then
  503.                     Call SA_SetErrMsg(GetLocString("sitearea.dll", "404201DC", ""))
  504.                 End If
  505.                 Exit Function
  506.             End If
  507.             Set objService = Nothing
  508.         End If
  509.  
  510.         '7) Setting return URL
  511.         WebName = GetWebSiteNo(F_strSiteID)
  512.         Call SA_TraceOut(SA_GetScriptFileName(), "New WebSite ID: " + CStr(WebName))
  513.         
  514.         Call SA_MungeURL(mstrReturnURL, "PKey",WebName)
  515.         Call SA_TraceOut(SA_GetScriptFileName(), "ReturnURL: " + mstrReturnURL)
  516.  
  517.         '5) Config Frontpage 
  518.         If( NOT ConfigFrontPage(F_strAdminName)) Then
  519.             Call SA_TraceOut(SA_GetScriptFileName(),  "ConfigFrontPage error: "+ CStr(Hex(Err.Number)) + " " + Err.Description)
  520.             If ( Len(GetErrMsg()) <= 0 ) Then
  521.                 Call SA_SetErrMsg(L_ERR_FRONTPAGE_CONFIGURATION)
  522.             End If
  523.             Exit Function
  524.         End If
  525.         CreateSite = TRUE
  526.         Call SA_TraceOut(SA_GetScriptFileName(), "CreateSite() return code: " + CStr(CreateSite))
  527.         
  528.          'release objects
  529.         'Set objRoot = nothing        
  530.     end function
  531.  
  532.     '----------------------------------------------------------------------------
  533.     'Function name        :CreateSiteUsers
  534.     'Description        :Serves in create administrator users
  535.     'Input Variables    :None 
  536.     'Output Variables    :None
  537.     'Returns            :Boolean (True if new site is created else returns False)
  538.     'Global Variables    :None
  539.     'Functions Used        :
  540.     '----------------------------------------------------------------------------
  541.     Function CreateSiteUsers(ByRef objRoot)
  542.         On Error Resume Next
  543.         Err.Clear
  544.         
  545.         CreateSiteUsers = False
  546.         'creates necessary ou's, users and groups, cleansup if 
  547.         'something fails
  548.         If F_strAccountLocation = "1" then
  549.             'creates necessary users , cleansup if something fails
  550.             if NOT HandleWrkgrpAndNTDC(objRoot) then
  551.                 exit function
  552.             end if
  553.         Elseif F_strAccountLocation = "2" Then
  554.             'valid the exist user and prompt the user when err
  555.             Dim objComputer
  556.             Dim oUser
  557.             Dim arrId
  558.             Dim strDomain
  559.             Dim strUser
  560.  
  561.             arrId = split(F_strAdminName,"\")
  562.  
  563.             If ubound(arrId) <> 1 Then
  564.                 SetErrMsg L_ERR_ADMINISTRATOR_NAME
  565.                 Exit Function
  566.             End If
  567.  
  568.             strDomain = arrId(0)
  569.             strUser = arrId(1)
  570.  
  571.             set objComputer = GetObject("WinNT://" & strDomain)
  572.             If Err.number <> 0 Then
  573.                 SetErrMsg SA_GetLocString("Sitearea.dll", _
  574.                             "C04201D4", _
  575.                             Array("WinNT://" & strDomain))
  576.                 Exit Function
  577.             End if
  578.  
  579.             Set oUser = objComputer.GetObject("user" , trim(strUser))
  580.             If Err.number <> 0 Then
  581.                 SetErrMsg L_ERR_ACCOUNT_NOT_FOUND
  582.                 Exit Function
  583.             End if        
  584.         End If
  585.         CreateSiteUsers = True
  586.     End Function
  587.  
  588.     '----------------------------------------------------------------------------
  589.     'Function name        :ConfigDirDACL
  590.     'Description        :Serves in set permission of directory
  591.     'Input Variables    :None 
  592.     'Output Variables    :None
  593.     'Returns            :Boolean (True if new site is created else returns False)
  594.     'Global Variables    :None
  595.     'Functions Used        :
  596.     '----------------------------------------------------------------------------
  597.  
  598.     Function ConfigDirDACL(strDir,strAdminName)    
  599.         On Error Resume Next
  600.         Err.Clear 
  601.         
  602.         ConfigDirDACL = False
  603.         
  604.         ' Set DACL entries for Anon and Admin users for Home Directory 
  605.          if (NOT SetDaclForRootDir(strDir,strAdminName)) then
  606.              Call SA_SetErrMsg(L_DACL_ERRORMESSAGE)
  607.             Call SA_TraceOut ("site_new", "Failed to set the DACL for root dir ")
  608.             Exit Function
  609.         end if        
  610.         ConfigDirDACL = True
  611.     End Function
  612.     
  613.     '----------------------------------------------------------------------------
  614.     'Function name        :ConfigFrontPage
  615.     'Description        :Serves in config front page
  616.     'Input Variables    :None 
  617.     'Output Variables    :None
  618.     'Returns            :Boolean (True if new site is created else returns False)
  619.     'Global Variables    :None
  620.     'Functions Used        :
  621.     '----------------------------------------------------------------------------
  622.     Function ConfigFrontPage(strAdminName)
  623.         On Error Resume Next
  624.         Err.Clear 
  625.         
  626.         Dim objService
  627.         Dim strUserName
  628.  
  629.         Set objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  630.         ConfigFrontPage = True
  631.  
  632.         '
  633.         ' Configure FrontPage Server Extensions if they are installed and were
  634.         ' selected by the user.
  635.         '
  636.         If ( TRUE = isFrontPageInstalled(objService) And _
  637.              UPLOADMETHOD_FPSE = F_strUploadMethod) Then
  638.              
  639.             ConfigFrontPage = False
  640.  
  641.             '
  642.             ' User name depends on account type
  643.             select case F_strAccountLocation
  644.             
  645.                 case "1"
  646.                     strUserName = G_strSysName & "\" & strAdminName
  647.                     
  648.                 case "2"
  649.                     strUserName = strAdminName
  650.                     
  651.                 case else
  652.                     Call SA_TraceOut(SA_GetScriptFileName(), "Function ConfigFrontPage encountered unexpected AccountLocation code: " + CStr(F_strAccountLocation))
  653.                     Exit Function                
  654.             end select
  655.  
  656.             ConfigFrontPage = UpdateFrontPage(True, G_strSiteName, strUserName)
  657.         End If
  658.     End Function
  659.  
  660.     '-------------------------------------------------------------------------
  661.     'Function name        :HandleWrkgrpAndNTDC
  662.     'Description        :Creates req users in case of Workgrp and NTDC scenario
  663.     'Input Variables    :objRoot
  664.     'Output Variables    :None
  665.     'Returns            :boolean
  666.     'Global Variables    :None    
  667.     '-------------------------------------------------------------------------
  668.     Function HandleWrkgrpAndNTDC( objRoot )
  669.         Err.Clear 
  670.         On Error Resume Next
  671.     
  672.         Dim objSAHelper
  673.         Dim strPassword
  674.         Dim bCreatingAnon
  675.         
  676.         HandleWrkgrpAndNTDC = FALSE
  677.  
  678.         'If we are creating Anonymous account we need to set these properties to
  679.         ' TRUE
  680.         ' 1) Password Never Expires
  681.         ' 2) User cannot change password
  682.  
  683.  
  684.         bCreatingAnon = False
  685.  
  686.         ' Create Admin user first because it is used for setting site operator
  687.         if ( Not blnCreateUser(objRoot, F_strAdminName, F_strAdminPswd, bCreatingAnon) ) then
  688.             Exit Function
  689.         End If
  690.         
  691.         
  692.         Set objSAHelper = server.CreateObject("ServerAppliance.SAHelper")
  693.         
  694.         if Err.number <> 0 then
  695.             Call SA_TraceOut ("site_new", "createobject for sahelper failed")
  696.             exit function
  697.         else
  698.             strPassword = objSAHelper.GenerateRandomPassword(14)
  699.             if Err.number <> 0 then
  700.                 Call SA_TraceOut ("site_new", "generate random password failed")
  701.                 Set objSAHelper = Nothing
  702.                 exit function
  703.             end if
  704.         end if            
  705.  
  706.         Set objSAHelper = Nothing
  707.                         
  708.         'Create Anonymous user for setting anonymous user settings in the web 
  709.         'site
  710.         SA_traceOut "G_strAnonName:", G_strAnonName
  711.         bCreatingAnon = True
  712.         '
  713.         'Set the pwd of the anonymous user, it needs to be used when we set the webvirdir object.
  714.         'That's because of the IIS security change, which won't install sub-authenticator from
  715.         'installation.
  716.         G_strAnonPwd = strPassword
  717.         SA_TraceOut "G_strAnonPwd:", G_strAnonPwd
  718.         if ( Not blnCreateUser(objRoot, G_strAnonName, strPassword, bCreatingAnon) ) then
  719.             Call blnDeleteUser(objRoot, F_strAdminName)
  720.             Exit Function
  721.         End If
  722.  
  723.         
  724.         HandleWrkgrpAndNTDC = TRUE
  725.     End Function
  726.  
  727.     '-------------------------------------------------------------------------
  728.     'Function name        :blnValidateInputs
  729.     'Description        :Validate Site identifier, directory path and admin 
  730.     '                     user
  731.     'Input Variables    :
  732.     'Output Variables    :None
  733.     'Returns            :boolean
  734.     'Global Variables    :None    
  735.     '-------------------------------------------------------------------------
  736.     Function blnValidateInputs()
  737.         Err.clear
  738.         On Error Resume Next        
  739.                 
  740.         blnValidateInputs = FALSE
  741.         
  742.         Dim arrFullName
  743.         
  744.         '1) Check whether the site Identifier exists
  745.         If F_strAccountLocation = "1" Then
  746.             if isValidSiteIdentifier(F_strSiteID, F_strAdminName, G_strSysName, True) = false then
  747.                 mintTabSelected = 0 
  748.                 SetErrMsg SA_GetLocString("Sitearea.dll", _
  749.                                     "C04200C1", _
  750.                                     Array(F_strSiteID))
  751.                 exit Function
  752.             end if
  753.         Elseif F_strAccountLocation = "2" Then
  754.             if isValidSiteIdentifier(F_strSiteID, "", "", False) = false then
  755.                 mintTabSelected = 0 
  756.                 SetErrMsg SA_GetLocString("Sitearea.dll", _
  757.                                     "C04200C1", _
  758.                                     Array(F_strSiteID))
  759.                 exit Function
  760.             end if
  761.         End If
  762.         
  763.  
  764.         '2) validates the dir and create the dir if necessary
  765.         if (NOT ValidateSitePath(F_strCreatePathChecked, F_strDir)) then
  766.             exit function
  767.         end if                    
  768.         
  769.         Call SA_TraceOut( "site_new", "validateinputs successful" )
  770.         blnValidateInputs = true
  771.     end function
  772.  
  773.     '-------------------------------------------------------------------------
  774.     'Function name        :blnCreateUser
  775.     'Description        :Function to create user
  776.     'Input Variables    :objRoot, strUserName, strPassword
  777.     'Output Variables    :None
  778.     'Returns            :Boolean 
  779.     'Global Variables    :None    
  780.     '                    
  781.     '-------------------------------------------------------------------------
  782.     Function blnCreateUser(objRoot, strUserName, strPassword, bCreatingAnon)
  783.         
  784.         Dim objUser            'holds user object
  785.         Dim flagPasswd
  786.  
  787.         Err.Clear
  788.         On Error Resume Next
  789.  
  790.         blnCreateUser = false
  791.  
  792.         ' create Admin user in SAM
  793.         Set objUser = objRoot.Create("user" , trim(strUserName))
  794.         objUser.setPassword(trim(strPassword))
  795.         objUser.FullName    = strUserName
  796.         objUser.Description = strUserName
  797.  
  798.         'If we are creating Anonymous account we need to set these properties to
  799.         ' TRUE
  800.         ' 1) Password Never Expires
  801.         ' 2) User cannot change password
  802.         If bCreatingAnon Then
  803.             flagPasswd = &H10040
  804.             objUser.Put "userFlags", flagPasswd
  805.         End If
  806.  
  807.         objUser.SetInfo()
  808.         
  809.         If Err.number <> 0 Then
  810.             mintTabSelected = 0    
  811.             If Err.number = &H800708C5 Then
  812.                 SetErrMsg L_ERR_PASSWORD_POLICY
  813.             Else
  814.                 SetErrMsg L_UNABLETOSET_PASSWORD_ERRORMESSAGE
  815.             End If
  816.             exit Function
  817.         end if
  818.  
  819.         'release objects
  820.         set objUser = nothing
  821.         SA_traceout "blncreateuser success: strUserName", strUserName
  822.  
  823.         blnCreateUser = true
  824.  
  825.     End function
  826.  
  827.     '-------------------------------------------------------------------------
  828.     'Function name        :blnCreateWebSite
  829.     'Description        :Creating new web site
  830.     'Input Variables    :None 
  831.     'Output Variables    :None
  832.     'Returns            :Boolean (True if new site is created else returns 
  833.     '                     False)
  834.     'Global Variables    :None    
  835.     '-------------------------------------------------------------------------
  836.     Function blnCreateWebSite(strSiteID, _
  837.                               strIPAddr, _
  838.                               strPort, _
  839.                               strHeader, _
  840.                               strDir, _
  841.                               strchkAllow, _
  842.                               selectActiveFormat, _
  843.                               strAdminName, _
  844.                               strDefaultPageText)
  845.         On Error Resume Next
  846.         Err.Clear
  847.  
  848.         Dim objService        'holds WMI connection object
  849.         Dim objMasterWeb    'holds MasterWeb Connection    
  850.         Dim instWeb            'holds intance web    
  851.         Dim retVal            'holds return value
  852.         Dim arrBindings        'holds arraybinidngs object
  853.         Dim nNewSiteNo        'holds new site number
  854.         Dim strSiteNum        'holds new site name
  855.         Dim objSetting        'holds WMI Connection object
  856.         Dim bIIS            'Allow IIS control password
  857.         Dim siteName
  858.  
  859.         Dim strAnonPropUserName,strAnonPropPwd
  860.     
  861.         'strAnonPropPwd holds the pwd of the anon user created
  862.         strAnonPropPwd = ""
  863.     
  864.             Call SA_TraceOut ("site_new", "In handle blnCreateWebSite function")
  865.  
  866.             blnCreateWebSite = FALSE
  867.         
  868.             nNewSiteNo = GetNewSiteNo()
  869.         
  870.             '
  871.             ' Delete any existing FrontPage Extension configuration for this new web site. We need
  872.             ' to do this because FPSE does not clean-up after itself when a site is deleted. If someone
  873.             ' manually deletes a site using the IIS snap-in, FPSE configuration information is left in the REG
  874.             ' and we need to clear that out so the previous setting do not interfere with this new site.
  875.             siteName = "W3SVC/"+CStr(nNewSiteNo)
  876.             Call SA_TraceOut(SA_GetScriptFileName(), "Calling UpdateFrontPage(false, " & siteName & ", " & strAdminName & ") to delete FPSE")
  877.             Call UpdateFrontPage("false", siteName, strAdminName)
  878.             
  879.             'Get ServerBindings Value 
  880.             arrBindings = array(GetBindings(strIPAddr, strPort, strHeader))
  881.                             
  882.             Set objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)    
  883.         
  884.             Set instWeb = objService.Get(GetIISWMIProviderClassName("IIs_WebService") & ".Name='W3SVC'")
  885.         
  886.             If Err.Number  <> 0 Then          
  887.                 SetErrMsg L_INFORMATION_ERRORMESSAGE
  888.                 Exit Function
  889.             End If
  890.                     
  891.             If IsIIS60Installed() Then
  892.                 
  893.                 ' In IIS 6.0 WMI, Create a new web site needs to call CreateNewSite 
  894.                 ' and it takes ServerBinding object as input argument instead of using 
  895.                 ' a array of strings for bindings
  896.                                     
  897.                 Dim arrObjBindings(0)
  898.  
  899.                 set arrObjBindings(0) = objService.Get("ServerBinding").SpawnInstance_
  900.  
  901.                 arrObjBindings(0).Port = strPort
  902.                 arrObjBindings(0).IP = strIPAddr
  903.                 arrObjBindings(0).Hostname = strHeader                    
  904.  
  905.                 ' Create the website thru 6.0 WMI provider
  906.                 instWeb.CreateNewSite strSiteID, arrObjBindings, strDir, nNewSiteNo
  907.                 
  908.             Else
  909.                 retVal = instWeb.CreateNewServer(nNewSiteNo, strSiteID,    arrBindings, strDir)
  910.                 
  911.             End If
  912.             
  913.             If Err.Number  <> 0 Then
  914.                 SetErrMsg L_CREATEFAIL_ERRORMESSAGE
  915.                 Exit Function
  916.             End If 
  917.  
  918.             instWeb.Put_(WBEMFLAG) ' register the object created
  919.             If Err.Number  <> 0 Then 
  920.                 SetErrMsg L_UPDATEFAIL_ERRORMESSAGE
  921.                 Exit Function
  922.             End If
  923.  
  924.             strSiteNum = instWeb.Name &  "/" & nNewSiteNo
  925.             ' Get the Internal Site Identifier of the created Web site
  926.             G_strSiteName = strSiteNum
  927.             
  928.             '1) Set ServerID property for newly created site
  929.             if MakeManagedSite(objService, strSiteNum,strSiteID) = false then
  930.                 SetErrMsg L_CRMANAGEDSITE_REGKEY_ERRORMESSAGE
  931.                 'delete site and exit
  932.                 retVal = DeleteWebSite( objService, strSiteNum )
  933.                 Exit Function
  934.             end if
  935.  
  936.             If F_strAccountLocation = "1" Then
  937.                 strAnonPropUserName=G_strAnonName                    
  938.                 'Set the pwd to the generated pwd for anon user
  939.                 strAnonPropPwd = G_strAnonPwd 
  940.             Else ' (F_strAccountLocation = "2")
  941.                 strAnonPropUserName = G_AnonUserName
  942.             End If
  943.             bIIS = True    
  944.  
  945.             if NOT SetAnonProp(objService, strSiteNum, strchkAllow, _
  946.                 strAnonPropUserName, strAnonPropPwd, bIIS) then
  947.                 retVal = DeleteWebSite( objService, strSiteNum )
  948.                 Exit Function
  949.             end if
  950.             
  951.             '2) Create Site Operator
  952.             if NOT blnCreateIISOperator(objService, strSiteNum,strAdminName) then
  953.                 retVal = DeleteWebSite( objService, strSiteNum )
  954.                 Call SA_TRACEOUT("blnCreateWebSite","Create Site Operator failed")
  955.                 Exit Function
  956.             end if
  957.  
  958.             '3) Set Access Read properties for Site                                    
  959.             if selectActiveFormat = "" then            
  960.                 Set objSetting =objService.Get(GetIISWMIProviderClassName("IIs_WebServiceSetting") & ".Name='W3SVC'")
  961.                 if objSetting.Name = "W3SVC" then    
  962.                     if objSetting.AccessExecute = TRUE and _
  963.                         objSetting.AccessScript = TRUE then
  964.                         selectActiveFormat = 2
  965.                     elseif objSetting.AccessExecute = false and _
  966.                         objSetting.AccessScript = TRUE then
  967.                         selectActiveFormat = 1
  968.                     elseif objSetting.AccessExecute = false and _
  969.                         objSetting.AccessScript = false then
  970.                         selectActiveFormat =0
  971.                     elseif isnull(objSetting.AccessExecute) and _
  972.                         isnull(objSetting.AccessScript) then
  973.                         selectActiveFormat = 0
  974.                     end if
  975.                 end    if
  976.                 'Release the object
  977.                 set objSetting = nothing
  978.             end if
  979.     
  980.             '4) Set execute perms for Site 
  981.             if NOT SetExecPerms(selectActiveFormat, objService, _
  982.                 strSiteNum) then                            
  983.                 retVal = DeleteWebSite( objService, strSiteNum )
  984.                 Exit Function
  985.             end if
  986.  
  987.             '5) Set Access Read properties for Site
  988.             if NOT SetApplRead( objService, strSiteNum) then
  989.                 retVal = DeleteWebSite( objService, strSiteNum )
  990.                 Exit Function
  991.             end if
  992.  
  993.             '6) Set default web page
  994.             if NOT SetWebDefaultPage( objService, strDefaultPageText, strSiteNum) then
  995.                 retVal = DeleteWebSite( objService, strSiteNum )
  996.                 Exit Function
  997.             end if
  998.  
  999.             '7) Start the Website
  1000.             retVal = StartWebSite(objService, strSiteNum )
  1001.  
  1002.         'next
  1003.         
  1004.         Call SA_TraceOut ( "site_new.asp", "blnCreateWebSite Suceesfull" )
  1005.         'release objects
  1006.         set objService = nothing
  1007.         set objMasterWeb = nothing
  1008.         blnCreateWebSite = true
  1009.     End function
  1010.  
  1011.     '-------------------------------------------------------------------------
  1012.     'Function name        :SetDaclForRootDir
  1013.     'Description        :Sets the DACL for root dir
  1014.     'Input Variables    :None 
  1015.     'Output Variables    :None
  1016.     'Returns            :Boolean
  1017.     'Global Variables    :F_strDir, G_strAnonName, F_strAdminName    
  1018.     '-------------------------------------------------------------------------
  1019.     Function SetDaclForRootDir(byref strDir, strAdminName)
  1020.         On Error Resume Next
  1021.         Err.Clear
  1022.  
  1023.         SetDaclForRootDir = FALSE
  1024.         
  1025.         Dim objService            'to hold WMI connection object
  1026.         Dim strTemp                'to hold temp value    
  1027.         Dim objSecSetting        'to hold security setting value    
  1028.         Dim objSecDescriptor    'to hold security descriptor value
  1029.         Dim strPath                'to hold Path 
  1030.         Dim objDACL                'to hold DACL value 
  1031.         Dim objSiteAdminAce        'to hold site ACE
  1032.         Dim objAdminAce            'to hold Admine ace 
  1033.         
  1034.         Dim objAnonAce            'to hold Anon ace            
  1035.         Dim objAuthAce            'to hold Auth ace
  1036.         Dim objDomainAce        'to hold domain admin ace
  1037.         Dim retval                'holds return value    
  1038.  
  1039.         Set objService = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  1040.         objService.security_.impersonationlevel = 3
  1041.  
  1042.         'get the sec seting for file
  1043.         strPath = "Win32_LogicalFileSecuritySetting.Path='" & strDir & "'"
  1044.         set objSecSetting = objService.Get(strPath)
  1045.         if Err.number <> 0 then
  1046.             Call SA_TraceOut ("site_new", "Failed to get Sec object for dir ")
  1047.             exit function
  1048.         end if
  1049.  
  1050.         'get the ace's for all req users
  1051.  
  1052.         If F_strAccountLocation = "1" Then
  1053.             '
  1054.             ' add access user to root dir
  1055.             '
  1056.             if NOT GetUserAce(objService, strAdminName , G_strSysName, _
  1057.                 CONST_FULLCONROL, objSiteAdminAce ) then
  1058.                 Call SA_TraceOut ("site_new", _
  1059.                     "Failed to get ACE object for Site Admin user ")
  1060.                     exit function
  1061.             end if
  1062.  
  1063.             if NOT GetUserAce(objService, G_strAnonName, G_strSysName, _
  1064.                 CONST_READEXEC, objAnonAce ) then
  1065.                 Call SA_TraceOut ( "site_new", _
  1066.                     "Failed to get ACE object for Anon user ")
  1067.                 exit function
  1068.             end if
  1069.             '
  1070.             ' add access group to root dir
  1071.             '
  1072.             if NOT GetGroupAce(objService, SA_GetAccount_Administrators() , GetComputerName(), _
  1073.                 CONST_FULLCONROL, objAdminAce ) then
  1074.                 Call SA_TraceOut ("site_new", _
  1075.                     "Failed to get ACE object for Admin user")
  1076.                 exit function
  1077.             end if
  1078.  
  1079.         Elseif F_strAccountLocation = "2" Then
  1080.             Dim arrId
  1081.             Dim strDomain
  1082.             Dim strUser
  1083.  
  1084.             arrId = split(F_strAdminName,"\")
  1085.  
  1086.             If ubound(arrId) <> 1 Then
  1087.                 SetErrMsg L_ERR_ADMINISTRATOR_NAME
  1088.                 Exit Function
  1089.             End If
  1090.  
  1091.             strDomain = arrId(0)
  1092.             strUser = arrId(1)
  1093.  
  1094.             'add access users in the location
  1095.             if NOT GetUserAce(objService, strUser , strDomain, _
  1096.                 CONST_FULLCONROL, objSiteAdminAce ) then
  1097.                 Call SA_TraceOut ("site_new", _
  1098.                     "Failed to get ACE object for Site Admin user ")
  1099.                 exit function
  1100.             end if
  1101.  
  1102.             'IUSR_hostname (anonymous username created by IIS)        
  1103.             if NOT GetUserAce(objService, G_AnonUserName , G_strSysName, _
  1104.                 CONST_READEXEC, objAnonAce ) then
  1105.                 Call SA_TraceOut ("site_new", _
  1106.                     "Failed to get ACE object for Admin user")
  1107.                 exit function
  1108.             end if
  1109.             'add access group in the location
  1110.  
  1111.             If ucase(strDomain) = ucase(G_strSysName) Then        
  1112.                 if NOT GetGroupAce(objService, SA_GetAccount_Administrators() , GetComputerName(), _
  1113.                     CONST_FULLCONROL, objAdminAce ) then
  1114.                     Call SA_TraceOut ("site_new", _
  1115.                         "Failed to get ACE object for Admin user")
  1116.                     exit function
  1117.                 end if
  1118.             Else                
  1119.                 if NOT GetGroupAce(objService, SA_GetAccount_Administrators() , GetComputerName(), _
  1120.                     CONST_FULLCONROL, objAdminAce ) then
  1121.                     Call SA_TraceOut ("site_new", _
  1122.                         "Failed to get ACE object for Admin user")
  1123.                     exit function
  1124.                 end if
  1125.                 if NOT GetGroupAce(objService, "Domain Admins" , strDomain,_
  1126.                     CONST_FULLCONROL, objDomainAce ) then
  1127.                     Call SA_TraceOut ("site_new", _
  1128.                         "Failed to get ACE object for Admin user")
  1129.                     exit function
  1130.                 end if
  1131.             End if
  1132.         End If
  1133.  
  1134.         Set objSecDescriptor = objService.Get("Win32_SecurityDescriptor").SpawnInstance_()
  1135.         if Err.Number <> 0 then
  1136.             Call SA_TraceOut ("site_new", _
  1137.                 "Failed to get create the Win32_SecurityDescriptor object ")
  1138.             exit function
  1139.         end if
  1140.  
  1141.         objSecDescriptor.Properties_.Item("DACL") = Array()
  1142.         Set objDACL = objSecDescriptor.Properties_.Item("DACL")
  1143.  
  1144.         If F_strAccountLocation = "1" Then
  1145.             objDACL.Value(0) = objSiteAdminAce
  1146.             objDACL.Value(1) = objAdminAce    
  1147.             objDACL.Value(2) = objAnonAce
  1148.         ElseIf F_strAccountLocation = "2" Then
  1149.             objDACL.Value(0) = objSiteAdminAce
  1150.             objDACL.Value(1) = objAdminAce    
  1151.             objDACL.Value(2) = objAnonAce
  1152.             If Not IsEmpty(objDomainAce) Then
  1153.                 objDACL.Value(3) = objDomainAce
  1154.             End If
  1155.         End If
  1156.  
  1157.         objSecDescriptor.Properties_.Item("ControlFlags") = 32772
  1158.         Set objSecDescriptor.Properties_.Item("Owner") = objSiteAdminAce.Trustee
  1159.  
  1160.         Err.Clear
  1161.         
  1162.         retval = objSecSetting.SetSecurityDescriptor( objSecDescriptor )    
  1163.         if Err.number <> 0 then
  1164.             Call SA_TraceOut ( "site_new", _
  1165.                 "Failed to set the Security Descriptor for Root dir ")
  1166.             exit function
  1167.         end if
  1168.  
  1169.         Call SA_TraceOut ("site_new", "In SetDaclForRootDir success" ) 
  1170.  
  1171.         SetDaclForRootDir = TRUE
  1172.         
  1173.         'Release the objects
  1174.         set objService = nothing
  1175.         set objSecSetting = nothing
  1176.         set objSecDescriptor = nothing
  1177.     End function
  1178.  
  1179.     '-------------------------------------------------------------------------
  1180.     'Function name        :blnDeleteUser
  1181.     'Description        :Deletes users if site not created
  1182.     'Input Variables    :None 
  1183.     'Output Variables    :None
  1184.     'Returns            :Boolean
  1185.     'Global Variables    :None    
  1186.     '-------------------------------------------------------------------------
  1187.     Sub blnDeleteUser(objRoot, strUserName)
  1188.         On Error Resume Next
  1189.         Err.Clear 
  1190.         
  1191.         Dim nretval            'to hold return value
  1192.             
  1193.         'deletes the Anonymous User from the System
  1194.         nretval = objRoot.Delete("user" , strUserName)
  1195.         If Err.Number <> 0 Then
  1196.             Call SA_TraceOut ("site_new", L_CANNOTDELETE_CREATEDUSERS_ERRORMESSAGE )
  1197.         End If        
  1198.     End Sub
  1199.     
  1200.     '-------------------------------------------------------------------------
  1201.     'Function name        :DeleteWebSite
  1202.     'Description        :Deletes the web site
  1203.     'Input Variables    :objService, strSiteNum
  1204.     'Output Variables    :None
  1205.     'Returns            :Boolean
  1206.     'Global Variables    :None    
  1207.     '-------------------------------------------------------------------------
  1208.     Function DeleteWebSite( objService, strSiteNum )
  1209.         On Error Resume Next
  1210.         Err.Clear
  1211.                 
  1212.         Dim strObjPath        'holds site collection
  1213.         Dim objWebSite        'holds instance of the site
  1214.         DeleteWebSite = FALSE
  1215.  
  1216.         strObjPath = GetIISWMIProviderClassName("IIs_WebServer") & ".Name=" & chr(34) & strSiteNum & chr(34)
  1217.         Set objWebSite = objService.Get(strObjPath)
  1218.         if Err.Number <> 0 then
  1219.             Call SA_TraceOut("site_new","Unable to get the web server object ")
  1220.             Exit Function
  1221.         End If
  1222.  
  1223.         'delete the object
  1224.         objWebSite.Delete_
  1225.         if Err.Number <> 0 then
  1226.             SA_TraceOut "site_new", "Unable to delete the web site "
  1227.             Exit Function
  1228.         End If
  1229.         
  1230.         DeleteWebSite = TRUE
  1231.         
  1232.         'Release the object
  1233.         set objWebSite = nothing
  1234.     End Function
  1235.  
  1236.  
  1237.     '-------------------------------------------------------------------------
  1238.     'Function name        :blnCreateIISOperator
  1239.     'Description        :creates operators for the site
  1240.     'Input Variables    :objService, strSiteNum 
  1241.     'Output Variables    :None
  1242.     'Returns            :Boolean
  1243.     'Global Variables    :None    
  1244.     '-------------------------------------------------------------------------
  1245.     Function blnCreateIISOperator(objService, strSiteNum,strAdminName)
  1246.         On Error Resume Next
  1247.         Err.Clear 
  1248.         
  1249.         Dim objACE                        'holds ACE
  1250.         Dim strQuery                    'holds Query string
  1251.         Dim objAdminACLInstanceSet        'holds Admin ACL instanceset
  1252.         Dim objAdminACLInstance            'holds Admin ACL instance
  1253.         
  1254.         blnCreateIISOperator = FALSE
  1255.         strQuery= GetIISWMIProviderClassName("IIs_AdminACL") & ".Name='" & strSiteNum &"'"
  1256.         set objAdminACLInstanceSet = objService.Get(strQuery)
  1257.         if err.number<>0 then
  1258.             'note action req
  1259.             SetErrMsg L_INFORMATION_ERRORMESSAGE
  1260.             exit function
  1261.         end if
  1262.         
  1263.         set objACE = objService.Get(GetIISWMIProviderClassName("IIs_ACE")).SpawnInstance_()
  1264.             
  1265.         if err.number <>0 then
  1266.             SetErrMsg L_INFORMATION_ERRORMESSAGE
  1267.             exit function
  1268.         end if
  1269.  
  1270.         objACE.Name = objAdminACLInstanceSet.Name
  1271.         objACE.AccessMask = 11
  1272.         objACE.AceFlags = 0
  1273.         objACE.AceType = 0
  1274.         objACE.Trustee = strAdminName
  1275.         objACE.Put_(WBEMFLAG)
  1276.         
  1277.         blnCreateIISOperator = TRUE
  1278.         
  1279.         'release objects
  1280.         set objACE = nothing
  1281.         set objAdminACLInstanceSet = nothing        
  1282.     End function
  1283.     
  1284.     '-------------------------------------------------------------------------
  1285.     'Function name        :ValidateSitePath
  1286.     'Description        :Validate Directory path, creates if necessary
  1287.     'Input Variables    :None
  1288.     'Output Variables    :None
  1289.     'Returns            :Boolean
  1290.     'Global Variables    :None    
  1291.     '-------------------------------------------------------------------------    
  1292.     Function ValidateSitePath(strCreatePathChecked,strFormDir)
  1293.         Err.Clear
  1294.         on error resume next
  1295.         
  1296.         Dim objFso                    'holds FileSystem object
  1297.         Dim strDir                    'holds Director path
  1298.         Dim strIndx                    'holds index value
  1299.         Dim strDriveName            'holds drive name                
  1300.         Dim strQuery                'holds Query string
  1301.         Dim objService                'holds WMI Connection
  1302.         Dim objDirList                'holds Virtualdirectory collection list
  1303.         Dim objDir                    'holds instance of Virtualdirectory list
  1304.         Dim strParentDir            'holds parent directory path    
  1305.         Dim nRetVal                    'holds return value
  1306.         Dim strDirPath                'holds directory path
  1307.         Dim strWinDirPath            'holds windows directory path
  1308.  
  1309.         ValidateSitePath = false
  1310.             
  1311.         Set objFso = server.CreateObject("Scripting.FileSystemObject")
  1312.         if Err.number <> 0 then
  1313.             SetErrMsg L_FILEINFORMATION_ERRORMESSAGE
  1314.             exit function
  1315.         end if            
  1316.     
  1317.         Call SA_TRACEOUT("ValidateSitePath", CStr(strCreatePathChecked))
  1318.         if strCreatePathChecked <> "true" then        
  1319.             'if folder does not exist, give error as folder does not exist
  1320.             if objFso.FolderExists(strFormDir)=false then
  1321.                 SetErrMsg L_DIR_DOESNOT_EXIST_ERRMSG
  1322.                 exit function
  1323.             end if
  1324.         end if
  1325.     
  1326.         Set objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  1327.         
  1328.         strQuery = "select path from " & GetIISWMIProviderClassName("IIs_WebVirtualDirSetting")
  1329.         set objDirList=objService.Execquery(strQuery)
  1330.         if Err.number <> 0 then
  1331.             SetErrMsg L_INFORMATION_ERRORMESSAGE
  1332.             exit function
  1333.         end if
  1334.  
  1335.         'truncate last '\' char
  1336.         if Right( strFormDir, 1 ) = "\" then
  1337.             strFormDir = Left(strFormDir, len(strFormDir) - 1)
  1338.         end if
  1339.  
  1340.         strParentDir = objFso.GetParentFolderName(strFormDir)
  1341.         
  1342.         for each objDir in objDirList            
  1343.             if  strComp(objDir.path, strFormDir, 0) = 0  OR  _
  1344.                 strComp(objDir.path, strParentDir, 0) = 0 then            
  1345.                 mintTabSelected = 0                
  1346.                 SetErrMsg L_DIR_FOR_WEB_SITES_TEXT
  1347.                 exit function
  1348.             end if
  1349.         next
  1350.  
  1351.         'check whether the Dir entered is Windows dir
  1352.         if len(objFso.GetSpecialFolder(0)) = len(strFormDir) then
  1353.             strWinDirPath = objFso.GetSpecialFolder(0)
  1354.         else
  1355.             strWinDirPath = objFso.GetSpecialFolder(0) & "\"
  1356.         end if
  1357.         
  1358.         strDirPath = mid(strFormDir,1,len(strWinDirPath))
  1359.                 
  1360.         if StrComp(trim(strDirPath),strWinDirPath,1) = 0 then
  1361.             
  1362.             SetErrMsg L_INVALID_DIR_PATH_ERRMSG
  1363.             mintTabSelected = 0
  1364.             
  1365.             exit Function
  1366.         
  1367.         end if
  1368.  
  1369.         nRetVal = CreateSitePath( objFso, strFormDir )
  1370.  
  1371.         if nRetVal <> CONST_SUCCESS then
  1372.  
  1373.             if nRetVal = CONST_INVALID_DRIVE then
  1374.  
  1375.                 SetErrMsg L_INVALID_DRIVE_ERRMSG
  1376.  
  1377.             elseif nRetVal = CONST_NOTNTFS_DRIVE then
  1378.     
  1379.                 SetErrMsg L_NOT_NTFS_DRIVE_ERRMSG
  1380.             
  1381.             else
  1382.             
  1383.                 SetErrMsg L_FAILED_CREATE_DIR_ERRMSG
  1384.             
  1385.             end if
  1386.  
  1387.             mintTabSelected = 0
  1388.             
  1389.             exit Function
  1390.  
  1391.         end if
  1392.  
  1393.  
  1394.         'release objects
  1395.         set objFso = nothing
  1396.         set objDirList = nothing
  1397.         set objService = nothing
  1398.  
  1399.         ValidateSitePath = true
  1400.     end function 
  1401.     
  1402. %>